How to return a string from char[] array using recursion loop.(java)
        Posted  
        
            by 
                Daniel
            
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Daniel
        
        
        
        Published on 2011-01-08T09:42:52Z
        Indexed on 
            2011/01/08
            9:53 UTC
        
        
        Read the original article
        Hit count: 161
        
I am very bed in recursion...
I need to convert a  char[] array by using recursion loop only, into string.
Without using for(),while()... loops. For example if i have char array: a[0]='H', a[1]='e', a[2]='l',a[3]= 'l',a[4]= 'o',
it returns H e l l o.
What I doing wrong?
 public String toFormattedString(char[] a)
 {
        int temp =a.length;
      if (a == null)
       return "null";
      if (a.length == 0)
       return "0";
       if( a.length == 1 )
           else  if( a[0] == a[a.length] )
         return toFormattedString (a[a.length -1])+a[a.length];
        © Stack Overflow or respective owner